package org.example.shixiguanli.service.impl;

import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import org.apache.commons.lang3.ObjectUtils;
import org.example.core.mysql.Where;
import org.example.core.service.impl.SimpleServiceImpl;
import org.example.shixiguanli.entity.TPracticeEntity;
import org.example.shixiguanli.model.TPracticeModel;
import org.example.shixiguanli.service.TPracticeService;
import org.springframework.context.annotation.Primary;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.User;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * Description:
 * Date: 2024/2/15 22:05
 */
@Service
@Primary
public class TPracticeServiceImpl extends SimpleServiceImpl<String, TPracticeModel, TPracticeEntity> implements TPracticeService {
    @Override
    public JSONObject getDetail(Map<String, Object> params) {
        String userId = ((User) SecurityContextHolder.getContext().getAuthentication().getPrincipal()).getUsername();
        TPracticeModel tPracticeModel = searchOne(Where.build().field("user_id").equal(userId).and().field("del_flag").equal(0));
        if (ObjectUtils.isEmpty(tPracticeModel)){
            return new JSONObject();
        }
        JSONObject practiceJsonObject = JSONUtil.parseObj(tPracticeModel);
        return practiceJsonObject;
    }
}
